package test.hashmap;

import java.util.HashMap;

import static com.google.common.collect.Maps.newHashMapWithExpectedSize;

/**
 * Cteate By Administrator on 2018/5/4 下午 1:39
 **/
public class hashMapMy {
     public static void main(String[] args) throws InterruptedException {

         HashMap hashMap = new HashMap();
         hashMap.put("A","A");
         System.out.println("=============");
         Thread.sleep(2000);
         HashMap hashMap2 = newHashMapWithExpectedSize(3);
         Long start=Runtime.getRuntime().freeMemory();
         new Thread(() -> {
             try {
                 System.out.println("=============");
                 Thread.sleep(2000);
             } catch (InterruptedException e) {
                 e.printStackTrace();
             }
//             for(int i=77777;i<88888;i++){
//                 //a%b == a&(b-1),当b是2的指数时,等式成立.
//                 System.out.println(15&i);
//             }
             for(int i=111188888;i<511188888;i++){
                 System.out.println(i);
                 hashMap.put(i,i%3);
             }
         }).start();

         new Thread(() -> {
             try {
                 System.out.println("=============");
                 Thread.sleep(2000);
             } catch (InterruptedException e) {
                 e.printStackTrace();
             }
//             for(int i=77777;i<88888;i++){
//                 //a%b == a&(b-1),当b是2的指数时,等式成立.
//                 System.out.println(15&i);
//             }
             for(int i=61188888;i<2111188888;i++){
                 System.out.println(i);
                 hashMap.put(i,i%3);
             }
         }).start();

         new Thread(() -> {

             for(int i=61188888;i<2111188888;i++){
                 try {
                 Thread.sleep(2000);

                 System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++");
                 Long end = Runtime.getRuntime().freeMemory();
                 System.out.println("一个HashMap对象占内存:" + (end - start));
                 } catch (InterruptedException e) {
                     e.printStackTrace();
                 }
             }
         }).start();

     }
}
